package com.ruoyi.project.jiaqin.downtrend.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.jiaqin.downtrend.domain.DownTrend;
import com.ruoyi.project.jiaqin.downtrend.service.IDownTrendService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 羽绒价格走势Controller
 *
 * @author admin
 * @date 2021-01-29
 */
@Controller
@RequestMapping("/jiaqin/downtrend")
public class DownTrendController extends BaseController
{
    private String prefix = "jiaqin/downtrend";

    @Autowired
    private IDownTrendService downTrendService;

    @RequiresPermissions("jiaqin:downtrend:view")
    @GetMapping()
    public String downtrend()
    {
        return prefix + "/downtrend";
    }

    /**
     * 查询羽绒价格走势列表
     */
    @RequiresPermissions("jiaqin:downtrend:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DownTrend downTrend)
    {
        startPage();
        downTrend.setDelFlag(0);
        List<DownTrend> list = downTrendService.selectDownTrendList(downTrend);
        return getDataTable(list);
    }

    /**
     * 导出羽绒价格走势列表
     */
    @RequiresPermissions("jiaqin:downtrend:export")
    @Log(title = "羽绒价格走势", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DownTrend downTrend)
    {
        List<DownTrend> list = downTrendService.selectDownTrendList(downTrend);
        ExcelUtil<DownTrend> util = new ExcelUtil<DownTrend>(DownTrend.class);
        return util.exportExcel(list, "downtrend");
    }

    /**
     * 新增羽绒价格走势
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存羽绒价格走势
     */
    @RequiresPermissions("jiaqin:downtrend:add")
    @Log(title = "羽绒价格走势", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DownTrend downTrend)
    {
        return toAjax(downTrendService.insertDownTrend(downTrend));
    }

    /**
     * 修改羽绒价格走势
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        DownTrend downTrend = downTrendService.selectDownTrendById(id);
        mmap.put("downTrend", downTrend);
        return prefix + "/edit";
    }

    /**
     * 修改保存羽绒价格走势
     */
    @RequiresPermissions("jiaqin:downtrend:edit")
    @Log(title = "羽绒价格走势", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DownTrend downTrend)
    {
        return toAjax(downTrendService.updateDownTrend(downTrend));
    }

    /**
     * 删除羽绒价格走势
     */
    @RequiresPermissions("jiaqin:downtrend:remove")
    @Log(title = "羽绒价格走势", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(downTrendService.deleteDownTrendByIds(ids));
    }
}
